package com.qingke.pms.command.user;

import com.qingke.pms.command.UserCommand;
import com.qingke.pms.pojo.Company;
import com.qingke.pms.pojo.User;
import com.qingke.pms.util.PMSConsole;

public class AddCompanyCommand extends UserCommand {

	public AddCompanyCommand(User user) {
		super(user);
	}

	@Override
	public void execute() {
		Company company=new Company();
		String code;
		while(true){
			code=PMSConsole.promptNotEmpty("code:");
			if(dao.isMaterialExistByCode(code)){
				PMSConsole.println("the code have been existed.");
				continue;
			}
			break; 
		}
		String name=PMSConsole.promptNotEmpty("name:");
		String description=PMSConsole.promptNotEmpty("description:");
		
		company.setCode(code);
		company.setName(name);
		company.setDescription(description);
		
		boolean isSuccess=dao.insertCompany(company);
		if(isSuccess)
			PMSConsole.println("add company success.");
		else
			PMSConsole.println("add company failed.");
	}

}
